<?php
/**
 * 项目：红河移动电路资源管理信息系统
 *
 * 公司：红河移动分公司
 *
 * @author 李朝应
 *
 * E-mail:lichaoying.hh@163.com
 *
 */
class Mail_model extends CI_Model {
   function __construct()
    {
        parent::__construct();
    }


 function getattr($id){

   $this->db->where("id", $id);
   $query = $this->db->get('req');
   if ($query->num_rows() > 0){
     foreach ($query->result() as $row) {
      $attr=$row->File_Path;
     }
  }
  return $attr;
 }
function getsend($id){
   $this->db->select("Main_Send as send");
   $this->db->where("id", $id);
   $query = $this->db->get('req');
   if ($query->num_rows() > 0){
     foreach ($query->result() as $row) {
      $rst=$row->send;
     }
  }
  return $rst;
 }
function gett1($id){
   $this->db->select("To_1 as t1");
   $this->db->where("id", $id);
   $query = $this->db->get('req');
   if ($query->num_rows() > 0){
     foreach ($query->result() as $row) {
      $rst1=$row->t1;
     }
  }
  return $rst1;
 }

function gett2($id){
   $this->db->select("To_2 as t2");
   $this->db->where("id", $id);
   $query = $this->db->get('req');
   if ($query->num_rows() > 0){
     foreach ($query->result() as $row) {
      $rst2=$row->t2;
     }
  }
  return $rst2;
 }
 function getorg3mail($name){
   $this->db->select("org3_email as email");
   $this->db->where("org3_name", $name);
   $query = $this->db->get('org3');
   if ($query->num_rows() > 0){
     foreach ($query->result() as $row) {
      $mail=$row->email;
     }
     return $mail;
  }else{
     return false;  
  }
 
 }
 function getmails($id){
     $send=$this->getsend($id);
     $t1=$this->gett1($id);
     $t2=$this->gett2($id);
     $str=$send.$t1.$t2;
     $mails="";
     while($pos=strpos($str,"，")){    //查找位置，这里的，要与数据库中的一致
        $org3=trim(substr($str,0,$pos)); //取第一逗号前的字串
        //echo $org3."<br>";
        if($this->getorg3mail($org3)){  //查询数据库中的email，只返回有地址的项。
            $mails.=$this->getorg3mail($org3).",";//存如变量中。
        }
        $str_=str_replace($org3."，","",$str);//替换成空，这里的，要与数据库中的一致
	    $str=$str_;
     }
     return $mails;
 }

 function getreqID($id){
    $this->db->select("	Requisition_ID as id");
    $this->db->where("id", $id);
    $query = $this->db->get('req');
    if ($query->num_rows() > 0){
      foreach ($query->result() as $row) {
       $id=$row->id;
     }
  }
  return $id;
 }

 function getUserName($login){
    $this->db->select("	us_name as name");
    $this->db->where("us_login",$login);
    $query = $this->db->get('user');
    if ($query->num_rows() > 0){
      foreach ($query->result() as $row) {
       $name=$row->name;
     }
  }
  return $name;
 }
 function getUserEmail($login){
    $this->db->select("	us_email as name");
    $this->db->where("us_login",$login);
    $query = $this->db->get('user');
    if ($query->num_rows() > 0){
      foreach ($query->result() as $row) {
       $name=$row->name;
     }
  }
  return $name;
 }
}//类定义结束
?>
